package com.prs.crm.domain.store;

import java.util.Collection;
import java.util.HashSet;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import com.prs.crm.domain.FlowCodeEntity;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.stock.ProductStore;

/**
 * 库房
 * 
 * @author prs.chenzhi
 * 
 */
@Entity
@Table(name = "stock_storeroom")
public class StoreRoom extends FlowCodeEntity{

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;

	@ManyToOne
	private StoreIn storein;

	private String name;

	// 编码
	private String roomcode;

	/*
	 * 库管
	 */
	@ManyToMany
	@OrderBy
	private Collection<Person> managers;

	@OneToMany(mappedBy = "room")
	@OrderBy
	@Cascade( { org.hibernate.annotations.CascadeType.ALL,
			org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Collection<StorePlace> places;
	
	
	@OneToMany(mappedBy = "room")
	@OrderBy
	@Cascade( { org.hibernate.annotations.CascadeType.ALL,
			org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Collection<ProductStore> productstore;

	private String remark;
	
	/**
	 * 批号
	 */
	private String batchNum;
	
	/**
	 * 库存数量
	 */
	private double stockNums;

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setManagers(Collection<Person> managers) {
		this.managers = managers;
	}

	public Collection<Person> getManagers() {
		return managers;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRemark() {
		return remark;
	}

	public void setPlaces(Collection<StorePlace> places) {
		this.places = places;
	}

	public Collection<StorePlace> getPlaces() {
		return places;
	}

	public void addManager(Person manager) {
		if (managers == null) {
			managers = new HashSet<Person>();
		}
		if (!managers.contains(manager))
			managers.add(manager);
	}

	public void removeManager(Person person) {
		if (managers != null)
			managers.remove(person);
	}

	public void addPlace(StorePlace place) {
		if (places == null) {
			places = new HashSet<StorePlace>();
		}
		if (!places.contains(place)) {
			place.setRoom(this);
			places.add(place);
		}
	}

	public void removePlace(StorePlace place) {
		if (places != null)
			places.remove(place);
	}



	public StoreIn getStorein() {
		return storein;
	}

	public void setStorein(StoreIn storein) {
		this.storein = storein;
	}

	public Collection<ProductStore> getProductstore() {
		return productstore;
	}

	public void setProductstore(Collection<ProductStore> productstore) {
		this.productstore = productstore;
	}

	public String getBatchNum() {
		return batchNum;
	}

	public void setBatchNum(String batchNum) {
		this.batchNum = batchNum;
	}

	public String getRoomcode() {
		return roomcode;
	}

	public void setRoomcode(String roomcode) {
		this.roomcode = roomcode;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public double getStockNums() {
		return stockNums;
	}

	public void setStockNums(double stockNums) {
		this.stockNums = stockNums;
	}



	
	
}
